package com.wechar_rpa.controller;

import com.wechar_rpa.model.User;
import com.wechar_rpa.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/users")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/{username}")
    public User getUser(@PathVariable String username) {
        return userService.getUserByUsername(username).orElse(null);
    }

    @GetMapping
    public List<User> getAllUsers() {
        return userService.findAll();
    }

    @PostMapping
    public User createUser(@RequestBody User user) {
        return userService.saveUser(user);
    }

    @GetMapping("/{username}/whitelist")
    public Boolean isWhitelisted(@PathVariable String username) {
        return userService.isUserWhitelisted(username);
    }

    @GetMapping("/whitelist")
    public List<User> getWhitelistedUsers() {
        return userService.getWhitelistedUsers();
    }
}